package com.captain.special.二叉树.中等;

import com.captain.leetcode.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * Des:
 *
 * @author XL
 * @Date 2022/5/18 17:57
 */
public class 二叉搜索树中第K小的元素230 {
    List<Integer> ans = new ArrayList<>();

    public int kthSmallest(TreeNode root, int k) {
        midRecur(root);
        return ans.get(k - 1);
    }

    public void midRecur(TreeNode node) {
        if (node == null) {
            return;
        }
        midRecur(node.left);
        ans.add(node.val);
        midRecur(node.right);
    }
}
